package com.hsh.dao.impl;

import com.hsh.bean.Blog;
import com.hsh.dao.AddFavorDao;
import com.hsh.util.DruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AddFavorDaoImpl extends DruidUtil implements AddFavorDao {
    @Override
    public boolean addFavorById(int bid) {
        int row = 0;
        Connection conn = null;
        PreparedStatement state = null;
        //ResultSet rs = null;
        try {
            conn = getConnection();
            //数据库中点赞数favor加1
            String sql ="update blog set favor=favor+1 where bid=?";
            state = conn.prepareStatement(sql);
            state.setInt(1,bid);
            row = state.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            close(conn, state, null);
        }
        return row>0;
    }
}
